// JavaScript Document
function getFormStr(formObj){//获取表单要提交的数据的字符串 formObj--表单对象
	var elements = formObj.elements;
	var postContent = "";
	for (i = 0; i < elements.length; ++i) {
		var element = elements[i];
		if(!element.name||element.getAttribute('allow'))continue;//对于没有设置name属性的表单不提交
		if (element.type == "text" || element.type == "textarea"|| element.type == "hidden") {
			postContent += encodeURIComponent(element.name) + "="+ encodeURIComponent(element.value) + "&";
		} else if (element.type == "select-one"
				|| element.type == "select-multiple") {
			var options = element.options, j, item;
			for (j = 0; j < options.length; ++j) {
				item = options[j];
				if (item.selected) {
					postContent += encodeURIComponent(element.name) + "="+ encodeURIComponent(item.value) + "&";
				}
			}
		} else if (element.type == "checkbox" || element.type == "radio") {
			if (element.checked) {
				postContent += encodeURIComponent(element.name) + "="+ encodeURIComponent(element.value) + "&";
			}
		} else if (element.type == "file") {
			if (element.value != "") {
				postContent += encodeURIComponent(element.name) + "="+ encodeURIComponent(element.value) + "&";
			}
		} else {
			postContent += encodeURIComponent(element.name) + "="+ encodeURIComponent(element.value) + "&";
		}
	}
	return postContent;
}
function setFormStr(formObj,data){//加载表单数据
	var elements = formObj.elements;
	for (i = 0; i < elements.length; ++i) {
		var element = elements[i];
		if(!element.name||element.getAttribute('switch'))continue;//对于没有设置name属性的 和 开关值为空的 则不加载当前的数据
		var key = element.getAttribute('name');
		var nameVal = eval("data."+key);
		if(nameVal){//当data数据中存在和name属性对于的值的时候,才设置当前数据的值
			if (element.type == "text" || element.type == "textarea"|| element.type == "hidden") {
				element.value = nameVal;
			}else if (element.type == "select-one" || element.type == "select-multiple"){
				var options = element.options, j, item;
				for (j = 0; j < options.length; ++j) {
					item = options[j];
					if(item.value==nameVal){
						item.selected = true;
					}
				}
			} else if (element.type == "radio") {
				if(element.value==nameVal){
					element.checked = true;
				}
			} else if (element.type == "checkbox") {//如果是复选框,针对多个被选择的情况
				var tp = [nameVal];
				if(nameVal.indexOf(',')>-1){
					tp = nameVal.split(',');
				}else if(nameVal.indexOf('|')>-1){
					tp = nameVal.split('|');
				}else if(nameVal.indexOf('#')>-1){
					tp = nameVal.split('#');			  
				}
				for(k=0;k<tp.length;k++){
					if(element.value==tp[k]){
						element.checked = true;
					}
				}
			}
		}
	}
}
